﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RegularTool
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Init();
        }
        private void Init()
        {
            try
            {
                List<string> strs = new List<string>();
                strs.Add("");
                strs.AddRange(RegularDef.RegularDefs);
                cmbRegular.ItemsSource = strs;
            }
            catch (Exception ex) { }
        }

        private void cmbRegular_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                string str = cmbRegular.SelectedItem.ToString();
                if (!string.IsNullOrEmpty(str))
                    txtRegular.Text = str;
            }
            catch (Exception ex) { }
        }

        private void btnMatch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string src = txtSrc.Text;
                if (src.Length < 1)
                    return;
                string pattern = txtRegular.Text.Trim();
                Regex regex = new Regex(pattern);
                var match = regex.Match(src);
                txtDst.Text = match.Value;
            }
            catch (Exception ex) { }
        }

        private void btnReplace_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string src = txtSrc.Text;
                if (src.Length < 1)
                    return;
                string pattern = txtRegular.Text.Trim();
                Regex regex = new Regex(pattern);
                var match = regex.Replace(src," ");
                txtDst.Text = match;
            }
            catch (Exception ex) { }
        }
    }
}
